package com.qezhhnjy.mall.coupon.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.coupon.HomeSubjectSpu;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.coupon.service.HomeSubjectSpuService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 专题商品 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "专题商品接口")
@Slf4j
@RequestMapping("/home-subject-spu")
public class HomeSubjectSpuController {
    @Resource
    private HomeSubjectSpuService homeSubjectSpuService;

    @GetMapping("/get")
    @Operation(summary = "根据id获取专题商品信息")
    public BaseResult<HomeSubjectSpu> get(Long id) {
        HomeSubjectSpu homeSubjectSpu = homeSubjectSpuService.getById(id);
        return BaseResult.success(homeSubjectSpu);
    }

    @PostMapping("/save")
    @Operation(summary = "新增专题商品信息")
    public BaseResult<HomeSubjectSpu> save(@RequestBody HomeSubjectSpu homeSubjectSpu) {
        homeSubjectSpuService.save(homeSubjectSpu);
        return BaseResult.success(homeSubjectSpu);
    }

    @PutMapping("/update")
    @Operation(summary = "更新专题商品信息")
    public BaseResult<HomeSubjectSpu> update(@RequestBody HomeSubjectSpu homeSubjectSpu) {
        homeSubjectSpuService.updateById(homeSubjectSpu);
        return BaseResult.success(homeSubjectSpu);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取专题商品信息")
    public BaseResult<Page<HomeSubjectSpu>> page(@RequestBody Page<HomeSubjectSpu> page) {
        homeSubjectSpuService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除专题商品信息")
    public BaseResult<Long> delete(Long id) {
        homeSubjectSpuService.removeById(id);
        return BaseResult.success(id);
    }
}

